//
//  QXConstants.h
//  Pods
//
//  Created by Qianxia on 2016/12/23.
//
//

#import <Foundation/Foundation.h>
#import <UIKit/UIKit.h>


//------------------------获取设备大小-----------------------------
//设备的Bounds
#define DeviceScreenBounds [[UIScreen mainScreen] bounds]

//设备的宽度
#define DeviceScreenWidth CGRectGetWidth(DeviceScreenBounds)

//设备的高度
#define DeviceScreenHeight CGRectGetHeight(DeviceScreenBounds)

//------------------------系统版本判断-----------------------------

//判断系统版本是否大于某个版本
#define SYSTEM_VERSION_GREATER_THAN_OR_EQUAL_TO(v)  ([[[UIDevice currentDevice] systemVersion] compare:v options:NSNumericSearch] != NSOrderedAscending)

#define SYSTEM_VERSION_EQUAL_TO(v)                  ([[[UIDevice currentDevice] systemVersion] compare:v options:NSNumericSearch] == NSOrderedSame)
#define SYSTEM_VERSION_GREATER_THAN(v)              ([[[UIDevice currentDevice] systemVersion] compare:v options:NSNumericSearch] == NSOrderedDescending)
#define SYSTEM_VERSION_LESS_THAN(v)                 ([[[UIDevice currentDevice] systemVersion] compare:v options:NSNumericSearch] == NSOrderedAscending)
#define SYSTEM_VERSION_LESS_THAN_OR_EQUAL_TO(v)     ([[[UIDevice currentDevice] systemVersion] compare:v options:NSNumericSearch] != NSOrderedDescending)

//判断系统大于ios7
#define IOS_7_OR_LATER SYSTEM_VERSION_GREATER_THAN_OR_EQUAL_TO(@"7")

//判断系统大于ios8
#define IOS_8_OR_LATER SYSTEM_VERSION_GREATER_THAN_OR_EQUAL_TO(@"8")
//判断系统大于ios9
#define IOS_9_OR_LATER SYSTEM_VERSION_GREATER_THAN_OR_EQUAL_TO(@"9")

#define IOS_10_OR_LATER SYSTEM_VERSION_GREATER_THAN_OR_EQUAL_TO(@"10")

//判断是否是IPad
#define IS_IPAD (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad)

//判断是否是iPhone
#define IS_IPHONE (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPhone)

/// App版本
#define APP_VERSION [[[NSBundle mainBundle] infoDictionary] objectForKey:@"CFBundleShortVersionString"]

/**
 *  @brief 将NSData转换成字符串
 *
 *  @param data NSData对象
 *
 *  @return 返回字符串
 */
#define NSStringFromData(data) [[NSString alloc] initWithData:data encoding:NSUTF8StringEncoding]

#define NSStringFromNumber(number) [@(number) description]

// NSUserDefaults实例
#define User_Defaults [NSUserDefaults standardUserDefaults]


//------------------------打印日志-----------------------------
//DEBUG  模式下打印日志,当前行
#ifdef DEBUG
#   define DLog(fmt, ...) NSLog((@"%s [Line %d] " fmt), __PRETTY_FUNCTION__, __LINE__, ##__VA_ARGS__);
#else
#   define DLog(...)
#endif

#ifdef DEBUG
#   define QXDLog(fmt, ...) NSLog((@"------------------------------------------------------ \n %s [Line %d] \n------------------------------------------------------" fmt), __PRETTY_FUNCTION__, __LINE__, ##__VA_ARGS__);
#else
#   define QXDLog(...)
#endif


// 重写NSLog,Debug模式下打印日志和当前行数
#define DEBUG_NSLog(FORMAT, ...) fprintf(stderr,"\n----------------------------------\n\nfunction:%s line:%d content:%s\n\n----------------------------------\n\n", __FUNCTION__, __LINE__, [[NSString stringWithFormat:FORMAT, ##__VA_ARGS__] UTF8String]);

// DEBUG  模式下打印日志,当前行 并弹出一个警告
#ifdef DEBUG
#   define QXULog(fmt, ...)  { UIAlertView *alert = [[UIAlertView alloc] initWithTitle:[NSString stringWithFormat:@"%s\n [Line %d] ", __PRETTY_FUNCTION__, __LINE__] message:[NSString stringWithFormat:fmt, ##__VA_ARGS__]  delegate:nil cancelButtonTitle:@"Ok" otherButtonTitles:nil]; [alert show]; }
#else
#   define QXULog(...)
#endif

#define QXLogMethod DLog(@"------------------------------------------------------ \n %@ \n------------------------------------------------------", NSStringFromSelector(_cmd))

#define QXLog(fmt) DLog(@"------------------------------------------------------ \n %@ \n------------------------------------------------------", fmt)

/**
 从AFNetworking的error中获取返回的错误信息
 
 @param error AFNetworking filed error
 
 @return Response String
 */
FOUNDATION_EXPORT NSString * QXGetAFResponseStringWithError(NSError *error);

@interface QXConstants : NSObject

@end
